package com.hex.ds.hdrs.period.job.vo.query;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.hex.ds.hdrs.common.utils.HdrsDateUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

@Data
public class PeriodJobQueryVo implements Serializable {

    private String appCode;

    private String jobCodeFuzzy;

    private String jobNameFuzzy;

    private String jobStatus;

    private String labelName;

    private List<String> startTime;

    private List<String> endTime;

    private List<String> bz;

    private String bizDateStart;

    private String bizDateEnd;

    private String startTimeStart;

    private String startTimeEnd;

    private String endTimeStart;

    private String endTimeEnd;

    private List<String> jobCodeList;

    private List<String> jobNameList;

    private List<String> pkIds;

    public String getJobCodeFuzzy() {
        if (StrUtil.isNotBlank(jobCodeFuzzy) && (jobCodeFuzzy.contains(",") || jobCodeFuzzy.contains("，"))) {
            return null;
        }
        return (StrUtil.isNotBlank(jobCodeFuzzy)) ? jobCodeFuzzy.toUpperCase() : null;
    }

    public List<String> getJobCodeList() {
        if (StrUtil.isNotBlank(jobCodeFuzzy) && (jobCodeFuzzy.contains(",") || jobCodeFuzzy.contains("，"))) {
            return Arrays.asList(jobCodeFuzzy.toUpperCase().replace("，", ",").split(","));
        }
        return jobCodeList;
    }

    public String getJobNameFuzzy() {
        if (StrUtil.isNotBlank(jobNameFuzzy) && (jobNameFuzzy.contains(",") || jobNameFuzzy.contains("，"))) {
            return null;
        }
        return jobNameFuzzy;
    }

    public List<String> getJobNameList() {
        if (StrUtil.isNotBlank(jobNameFuzzy) && (jobNameFuzzy.contains(",") || jobNameFuzzy.contains("，"))) {
            return Arrays.asList(jobNameFuzzy.replace("，", ",").split(","));
        }
        return jobNameList;
    }

    public String getBizDateStart() {
        if (CollectionUtil.isNotEmpty(bz) && bz.size() == 2) {
            return bz.get(0);
        }
        return HdrsDateUtil.getYesterDate();
    }

    public String getBizDateEnd() {
        if (CollectionUtil.isNotEmpty(bz) && bz.size() == 2) {
            return bz.get(1);
        }
        return HdrsDateUtil.getCurrentDate();
    }

    public String getStartTimeStart() {
        if (CollectionUtil.isNotEmpty(startTime) && startTime.size() == 2) {
            return cn.hutool.core.date.DateUtil.formatDateTime(cn.hutool.core.date.DateUtil.parse(startTime.get(0), "yyyy-MM-ddHH:mm:ss"));
        }
        return startTimeStart;
    }

    public String getStartTimeEnd() {
        if (CollectionUtil.isNotEmpty(startTime) && startTime.size() == 2) {
            return cn.hutool.core.date.DateUtil.formatDateTime(cn.hutool.core.date.DateUtil.parse(startTime.get(1), "yyyy-MM-ddHH:mm:ss"));
        }
        return startTimeEnd;
    }

    public String getEndTimeStart() {
        if (CollectionUtil.isNotEmpty(endTime) && endTime.size() == 2) {
            return cn.hutool.core.date.DateUtil.formatDateTime(cn.hutool.core.date.DateUtil.parse(endTime.get(0), "yyyy-MM-ddHH:mm:ss"));
        }
        return endTimeStart;
    }

    public String getEndTimeEnd() {
        if (CollectionUtil.isNotEmpty(endTime) && endTime.size() == 2) {
            return cn.hutool.core.date.DateUtil.formatDateTime(cn.hutool.core.date.DateUtil.parse(endTime.get(1), "yyyy-MM-ddHH:mm:ss"));
        }
        return endTimeEnd;
    }
}
